//
//  SlidTwoLabelView.m
//  Assistant
//
//  Created by 魏延龙 on 2020/8/5.
//  Copyright © 2020 张继明. All rights reserved.
//

#import "SlidTwoLabelView.h"

@interface SlidTwoLabelView ()

// 上方描述文字
@property(nonatomic, strong) UILabel *desTopLabel;
// 下方描述文字
@property(nonatomic, strong) UILabel *desBottomLabel;

@end

@implementation SlidTwoLabelView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupViews];
    }
    return self;
}

-(void)setupViews {
    // 考虑到label 需要换行自适应高度 使用约束
    self.desTopLabel = [[UILabel alloc] init];
    {
        self.desTopLabel.text = self.contentTitle;
        self.desTopLabel.font = [UIFont fontWithName:@"PingFangTC-Medium" size:24];
        self.desTopLabel.textColor = [UIColor whiteColor];
        self.desTopLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [self.desTopLabel sizeToFit];
        [self addSubview:self.desTopLabel];
    }
    
    self.desBottomLabel = [[UILabel alloc] init];
    {
        self.desBottomLabel.text = self.contentDes;
        self.desBottomLabel.font = [UIFont systemFontOfSize:14];
        self.desBottomLabel.textColor = [UIColor whiteColor];
        self.desBottomLabel.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:self.desBottomLabel];
    }
    
    NSString *v1  = @"V:|-0-[desTopLabel]";
    NSString *v2  = @"V:[desBottomLabel]-0-|";
    NSString *h1 = @"H:|-20-[desTopLabel]-20-|";
    NSString *h2 = @"H:|-20-[desBottomLabel]-20-|";
    
    NSDictionary *viewsDic1 = @{@"desTopLabel":self.desTopLabel};
    NSDictionary *viewsDic2 = @{@"desBottomLabel":self.desBottomLabel};
    
    NSArray *v1a = [NSLayoutConstraint constraintsWithVisualFormat:v1 options:0 metrics:nil views:viewsDic1];
    NSArray *v2a = [NSLayoutConstraint constraintsWithVisualFormat:v2 options:0 metrics:nil views:viewsDic2];
    
    NSArray *h1a = [NSLayoutConstraint constraintsWithVisualFormat:h1 options:0 metrics:nil views:viewsDic1];
    NSArray *h2a = [NSLayoutConstraint constraintsWithVisualFormat:h2 options:0 metrics:nil views:viewsDic2];
    
    //一般需要把约束添加到父view上
    [self addConstraints:v1a];
    [self addConstraints:v2a];
    [self addConstraints:h1a];
    [self addConstraints:h2a];
}

-(void)setContentTitle:(NSString *)contentTitle {
    _contentTitle = contentTitle;
    self.desTopLabel.text = contentTitle;
}

-(void)setContentDes:(NSString *)contentDes {
    _contentDes = contentDes;
    self.desBottomLabel.text = contentDes;
}

-(void)setContentDeseNumLines:(NSInteger)contentDeseNumLines {
    _contentDeseNumLines = contentDeseNumLines;
    self.desBottomLabel.numberOfLines = contentDeseNumLines;
    self.desBottomLabel.font = [UIFont fontWithName:@"PingFangTC-Medium" size:24];
    [self.desBottomLabel sizeToFit];
}
@end
